package mytest.ssw.www.myandroidproject.thread;

import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ImageView;


import mytest.ssw.www.myandroidproject.net.MyPOST;

/**
 * Created by 73409 on 2015/10/25.
 */
public class HttpPostThread implements Runnable {

Handler hand;
    private String url;
    Imageback imageback;
    private MyPOST myGet = new MyPOST();
    Handler handle = new Handler()
    {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            imageback.getback((Bitmap)msg.obj);
        }
    };
    public HttpPostThread(Handler hand, String url) {

        // 拼接访问服务器完整的地址
       this. url = url;

    }
    public HttpPostThread( String url) {

        // 拼接访问服务器完整的地址
        this. url = url;

    }

    @Override
    public void run() {
        // 获取我们回调主ui的message
        Message msg = handle.obtainMessage();
        Bitmap bitmap;
        try {
            bitmap = (Bitmap)myGet.DoPOSTImage(url);
            msg.obj = bitmap;
            // 给主ui发送消息传递数据
            handle.sendMessage(msg);
        }catch (Exception e)
            {
                Log.v("error", "图片获取错误");
                handle.sendMessage(null);
                e.printStackTrace();
            }

    }
    public void setback(Imageback imageback )
    {this.imageback = imageback;

    }
 public    interface  Imageback
    {
        public void getback(Bitmap bitmap);

    }
}
